package com.gridsum.yaml.parse;

import com.gridsum.yaml.schema.EdgeCommonConfig;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class ParseFromFile {

    public EdgeCommonConfig parseFromFile(File file) throws IOException {
        File canonicalFile = file.getCanonicalFile();
        System.out.println("canonicalFile:" + canonicalFile);

        FileReader yamlFileReader = new FileReader(canonicalFile);

        Yaml yaml = new Yaml();

        EdgeCommonConfig edgeCommonConfig = yaml.loadAs(yamlFileReader, EdgeCommonConfig.class);
        yamlFileReader.close();
        return edgeCommonConfig;
    }

}
